// pages/Component/PageSwitch/PageSwitch.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pages:{
      type:Number,
      value: 1
    },
    refresh: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    activepage: 1
  },

  observers: {
    'refresh': function(){
      this.setData({
        activepage: 1
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onTurnLast(){
      var temp = this.properties.activepage - 1;
      this.setData({
        activepage: temp
      })
      this.pageNumSent();
    },
    onTurnNext(){
      var temp = this.properties.activepage + 1;
      this.setData({
        activepage: temp
      })
      this.pageNumSent();
    },
    onClick(event){
      var temp = event.currentTarget.dataset.value;
      this.setData({
        activepage: temp
      })
      this.pageNumSent();
    },

    //向页面发送所在页码
    pageNumSent: function(){
      var page = this.data.activepage;
      this.triggerEvent('getPage', page)
    }
  }
})
